#include "Cpersuit.h"
#include <stdlib.h>
#include <unistd.h>

void
first_test(unsigned int run, Cps_Stopwatch watches[])
{
	unsigned int i;
	unsigned int *array;

	cps_stopwatch_start(&watches[0]);
	array = calloc(run, sizeof(*array));
	cps_stopwatch_stop(&watches[0]);

	cps_stopwatch_start(&watches[1]);
	for (i = 0; i < run; i++)
	{
		array[i] = i;
	}
	cps_stopwatch_stop(&watches[1]);

	free(array);
}

void
second_test(unsigned int run, Cps_Stopwatch watches[])
{
	unsigned int *it;
	unsigned int *end;
	unsigned int *array;

	cps_stopwatch_start(&watches[0]);
	array = malloc(run * sizeof(*array));
	usleep(run);
	cps_stopwatch_stop(&watches[0]);

	cps_stopwatch_start(&watches[1]);
	for (it = array, end = it + run; it != end; it++)
		*it = it - array;

	cps_stopwatch_stop(&watches[1]);

	free(array);
}
	

CPS_RUN_LIST
	CPS_RUN("C-Array", "Maybe slow", first_test, 0, 10000, 10,  
			CPS_TEST("Alloc", CPS_O_LINEAR),
			CPS_TEST("Assign", CPS_O_LINEAR)
		),
	CPS_RUN("C-Array", "Supposedly optimised", second_test, 0, 10000, 10,
			CPS_TEST("Alloc", CPS_O_LINEAR),
			CPS_TEST("Assign", CPS_O_LINEAR)
		)
CPS_RUN_LIST_END

